package Data;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.swing.Box.Filler;

public class CopyOfLogWriter {
	public void writeLog(String msg_buf, String log_path) {
		
		
		File w_file = null;
		BufferedReader buffRead = null;
		BufferedWriter buffWrite = null;
		
		String fileContent = "";
		int b = -1;
		
		if (log_path.length() == 0) {
			System.out.println("WriteLog Fail");
			return;
		}
		
		try {
			w_file = new File(log_path);
			buffRead = new BufferedReader(new FileReader(w_file));
			
			while ((b = buffRead.read()) != -1) {
				fileContent += (char) b;
			}
			buffRead.close();
			buffWrite = new BufferedWriter(new FileWriter(w_file));
			
			String buf = Memory.mmr_log;
			
			String write_str = fileContent + buf;
			
			buffWrite.write(write_str, 0, write_str.length());
			buffWrite.flush();
			
			Memory.mmr_log = "";
			
		} catch (IOException e) {
			System.out.println("Error " + e.toString());
			e.printStackTrace();
			System.exit(-2);
		} finally {
			try {
				buffWrite.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
